<div id="templatemo_upcomming_event" class="container_wapper">
    <div class="container">
        <h1 align="center" style="font-family: calibri; margin-bottom: 20px;"> -------------------Profil-------------------</h1>

        <table id="table-content">
            <form id="submitRequest" name="submitRequest" action="<?php echo site_url('transaksi/do_update_profil'); ?>" method="post" enctype="multipart/form-data">
                <tr>
                    <td align="left">Nama</td>
                    <td>:</td>                    
                    <td><?php echo $this->session->userdata('nama');  ?></td>
<!--                    <td><input type="text" name="nama" id="nama" value="<?php echo $this->session->userdata('nama'); ?>"/></td> -->
                </tr>
                <tr>
                    <td align="left">No HP</td>
                    <td>:</td>                    
                    <td><?php echo $this->session->userdata('no_hp');  ?></td>
<!--                <td><input type="text" name="no_hp" id="no_hp" value="<?php echo $this->session->userdata('no_hp'); ?>"/></td> -->
                </tr>
                <tr>
                    <td align="left">Email</td>
                    <td>:</td>
                    <td><?php echo $this->session->userdata('email');  ?></td>
<!--                <td><input type="text" name="email" id="email" value="<?php echo $this->session->userdata('email'); ?>"/> -->
                </tr>
                <tr>
                    <td align="left">Saldo Saat Ini</td>
                    <td>:</td>
                    <td><?php echo number_format($saldo, 0, ',', '.');  ?></td>
                </tr>                   
                <tr>
                    <td align="left">Kata Sandi Baru</td>
                    <td>:</td>
                    <td><input type="password" name="sandibaru" id="sandibaru"/></td>
                </tr>                    
                <tr>
                    <td align="left">Confirm Kata Sandi Baru</td>
                    <td>:</td>
                    <td><input type="password" name="confirmsandibaru" id="confirmsandibaru"/></td>
                </tr>                    

            </form>
            <tr>
                <td></td>
                <td></td>
                <td><input type="button" id="update_profil" name="update_profil" class="button_blue" value="Update"></td>
            </tr>
        </table>
    </div>
</div>
<script>
    $(function() {
        $("#update_profil").click(function(event) {
            var v_sandi_baru = document.getElementById('sandibaru').value;
            var v_confirm_sandi_baru = document.getElementById('confirmsandibaru').value;
            
            if (v_sandi_baru != v_confirm_sandi_baru ) {
                show_alert("Konfirmasi Sandi Baru tidak cocok");
            } else if (v_sandi_baru === "") {
                show_alert("Sandi Baru tidak boleh kosong");
            } else {
                show_dialog("Silahkan tunggu, transaksi anda sedang kami proses...");
                $.ajax({
                    url: '<?php echo base_url(); ?>index.php/transaksi/pre_update_profil',
                    type: "POST",
                    timeout : 30000,
                    data: {
                        sandi_baru: v_sandi_baru,
                        confirm_sandi_baru: v_confirm_sandi_baru,
                        '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
                    },
                    success: function(result)
                    {
                        var obres = $.parseJSON(result);
                        var err_code = obres.err_code;

                        if (err_code !== "00") {
                            hide_dialog(obres.msg);
                        }
                        else
                        {
                            hide_dialog("");
                            alert("Update berhasil dilakukan");
                            $("#submitRequest").submit();
                        }
                    },
                    error: function()
                    {
                        hide_dialog("Terdapat masalah dengan koneksi internet anda, silahkan coba kembali.");
                    }
                });
            }
        });
    });
</script>
</body>
</html>